package com.ljx.rabbit.controller;

import com.ljx.rabbit.result.R;
import com.ljx.rabbit.util.AliOSSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "上传")
@CrossOrigin
@Slf4j
@RequestMapping("/upload")
@RequiredArgsConstructor
public class UploadController {
    private final AliOSSUtils aliOSSUtils;
    @PostMapping
    @ApiOperation(value = "上传图片")
    public R<List<String>> upload(List<MultipartFile> files) throws IOException {
        log.info("上传图片:{}",files);
        List<String> list=new ArrayList<>();
        for (MultipartFile file : files) {
            list.add(aliOSSUtils.upload(file));
        }
        log.info("上传图片:{}",list);
        return R.success(list);
    }
}
